package com.atguigu.day01;

//2个售货员卖50张票、、、

class Ticket{
    //初始50张票
    private int num = 50;
    //需要有卖票这个方法
    public synchronized void saled(){
        if(num>0) {
            System.out.println(Thread.currentThread().getName()+"卖了"+(num--)+"张票，还剩"+num+"张票");
        }
    }
}
public class Demo1 {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        //线程  操作资源类

        new Thread(()->{for (int i = 0; i < 50; i++) ticket.saled();},"A").start();
        new Thread(()->{for (int i = 0; i < 50; i++) ticket.saled();},"B").start();
        new Thread(()->{for (int i = 0; i < 50; i++) ticket.saled();},"C").start();

    }

}
